/**
 * 
 */
package org.jackysoft.controller.base;

import java.util.Collection;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.base.BaseOption;
import org.jackysoft.entity.base.RootEntity;
import org.jackysoft.entity.nosql.SearchResult;
import org.jackysoft.query.RunnerQuery;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhuozhengsoft.pageoffice.BorderStyleType;
import com.zhuozhengsoft.pageoffice.OpenModeType;
import com.zhuozhengsoft.pageoffice.PageOfficeCtrl;
import com.zhuozhengsoft.pageoffice.wordwriter.WordDocument;


/**
 * @author qujiakang
 * 
 */
public class AbstractController<T extends RootEntity> {
	
	protected static final Log log = LogFactory.getLog(AbstractController.class);	
	
	/**
	 * 对象初始化方法
	 */

	@PostConstruct
	public void initilize() {

	}

	/**
	 * 对象销毁前调用
	 */
	@PreDestroy
	public void destory() {

	}

	@RequestMapping("/index")
    public void index(){
		
	}
	
	@RequestMapping("/save-update")
	public void saveupdate() throws Exception{
		
	}

	@RequestMapping("/get")
	public void get(@ModelAttribute T bean) {
	
	}
	
	@RequestMapping("/edit")
	public void edit(@ModelAttribute T bean){
		
	}
	

	@RequestMapping("/gets")
	public void gets(){
		
	}
	
	@RequestMapping("/query")
	public void query(@ModelAttribute RunnerQuery query,int page,int row){
		
	}
	
	@RequestMapping("/pager")
	public void pager(int page,int row){
		
	}
	
	@RequestMapping("/save")
	public void save(@ModelAttribute T bean){
		
	}
	
	@RequestMapping("/save-all")
	public void saves(@ModelAttribute Collection<T> beans){
		
	}
	
	@RequestMapping("/remove")
	public void remove(String id){
		
	}
	
	@RequestMapping("/removes")
	public void removes(Collection<T> id){
		
	}
	
	@RequestMapping("/update")
	public void update(@ModelAttribute T bean){
		
	}
	
	@RequestMapping("/updates")
	public void updates(@ModelAttribute T bean){
		
	}
	
	@RequestMapping("/download")
	public void download(String id){
		
	}
	
	@RequestMapping("/start")
	public void start(){
		
	}

	@RequestMapping(value= "/createup",method=RequestMethod.POST)
	public void createup(Part part,@ModelAttribute T bean) {
	   
	}

	@RequestMapping(value= "/upload",method=RequestMethod.POST)
	public void upload(Part part,@ModelAttribute T bean)  {
		
	}

	@RequestMapping(value= "/uploads",method=RequestMethod.POST)
	public void uploads(Part[] part,@ModelAttribute T bean){
		
	}

	@RequestMapping(value= "/upload-props")
	public void updateprops(@ModelAttribute String id,@ModelAttribute String props) {
		
	}
	
	@RequestMapping("/json")
	public @ResponseBody T json(String id,@ModelAttribute RunnerQuery query,T bean) throws Exception {
			
		return bean;
	}

	@RequestMapping("/jsons")
	public @ResponseBody Collection<T> jsons(String id,@ModelAttribute RunnerQuery query,@ModelAttribute Collection<T> beans) throws Exception {
			
		return beans;
	}
	
	@RequestMapping("/sorted")
	public void sorted(Collection<T> beans){
		
	}
    
	@RequestMapping("/sorted")
	public Collection<T> ztree(String id,Collection<T> beans) {
		
		return beans;
	}
	
	
	@RequestMapping("/input")
	public void input()  {
		
	}

	@RequestMapping("/options")
	public void options(@ModelAttribute RunnerQuery query,@ModelAttribute Collection<BaseOption> options)  {
	
	}
	
	@RequestMapping("/search")
	public void search(@ModelAttribute RunnerQuery query,Collection<SearchResult> results){
		
	}
	
	
	public PageOfficeCtrl pageOffice(String localName, String saveDataUrl,
			String saveFileUrl, String openUrl, OpenModeType openModeType,
			HttpServletRequest request, HttpServletResponse response) {
		String basePath = request.getScheme() + "://" + request.getServerName()
				+ ":" + request.getServerPort() + request.getContextPath()
				+ "/";
		WordDocument doc = new WordDocument();
		PageOfficeCtrl poCtrl1 = new PageOfficeCtrl(request);
		poCtrl1.setServerPage(basePath + "poserver.do"); // 此行必须
		// 设置界面样式

		poCtrl1.setBorderStyle(BorderStyleType.BorderThin);
		// 添加自定义工具条按钮
		poCtrl1.addCustomToolButton("保存", "poSave()", 1);
		poCtrl1.addCustomToolButton("关闭", "poNext()", 6);
		boolean readonly = true;
		// 隐藏工具栏
		poCtrl1.setOfficeToolbars(readonly);
		poCtrl1.setCustomRibbon("ribbon");
		poCtrl1.setMenubar(readonly);
		// 设置保存文档的服务器页面

		poCtrl1.setSaveDataPage(basePath + saveDataUrl);
		poCtrl1.setSaveFilePage(basePath + saveFileUrl);
		poCtrl1.setWriter(doc);
		poCtrl1.webOpen(basePath + openUrl, openModeType, localName);
		poCtrl1.setTagId("PageOfficeCtrl1"); // 此行必须
		return poCtrl1;
	}

}
